<div class="panel">
    <div class="panel_content">
        <h2><%= h @tour_group.number %></h2>
        <%= render :partial => "shared/back_link" %>
        |<%= render :partial => "shared/edit_link", :locals =>{:url => edit_tour_group_path(@tour_group)} %>
        |<%= render :partial => "shared/destroy_link", :locals =>{:url => @tour_group, :name => "收支表“#{@tour_group.number}”"} %>
        <br/>
        <br/>
		<% if flash[:notice] %>
        <div id="notice">
            <%= flash[:notice] %>
        </div>
        <% end %>
        <table class="form">
            <tr>
                <th>
                    团号
                </th>
                <td>
                    <%= h @tour_group.number %>
                </td>
                <th>
                    序号
                </th>
                <td>
                    <%= h @tour_group.sequence %>
                </td>
                <th>
                    日期
                </th>
                <td colspan="3">
                    <%= h @tour_group.during_start %>
                    <%= " 至 #{@tour_group.during_end}" unless @tour_group.during_end.nil? %>
                </td>
            </tr>
            <tr>
                <th>
                    国籍
                </th>
                <td>
                    <%= h @tour_group.nationality.name unless @tour_group.nationality.nil? %>
                </td>
                <th>
                    人数
                </th>
                <td>
                    <label title="成人">
                        <%= @tour_group.people %>
                    </label>
                    .
                    <label title="儿童">
                        [<%= @tour_group.children %>]
                    </label>
                </td>
                <th>
                    客源
                </th>
                <td colspan="3">
                    <%= h @tour_group.customer.name unless @tour_group.customer.nil? %>
                </td>
            </tr>
            <tr>
                <th>
                    行程概述
                </th>
                <td colspan="7">
                    <%= h @tour_group.summary %>
                </td>
            </tr>
            <tr>
                <th>
                    酒店
                </th>
                <td>
                    <%= h @tour_group.lodging.hotel.name unless @tour_group.lodging.nil? || @tour_group.lodging.hotel.nil? %>
                </td>
                <th>
                    房费
                </th>
                <td colspan="5">
                    <%= number_to_rmb @tour_group.lodging.lodging_cost unless @tour_group.lodging.nil? %>
                </td>
            </tr>
            <tr>
                <th>
                    导游
                </th>
                <td>
                    <%= h @tour_group.guide_involved.guide.name unless @tour_group.guide_involved.nil? || @tour_group.guide_involved.guide.nil? %>
                </td>
                <th>
                    餐费
                </th>
                <td>
                    <%= number_to_rmb @tour_group.guide_involved.food_cost unless @tour_group.guide_involved.nil? %>
                </td>
                <th>
                    门票
                </th>
                <td>
                    <%= number_to_rmb @tour_group.guide_involved.attraction_ticket_cost unless @tour_group.guide_involved.nil? %>
                </td>
                <th>
                    导贴
                </th>
                <td>
                    <%= number_to_rmb @tour_group.guide_involved.subsidy_for_guide unless @tour_group.guide_involved.nil? %>
                </td>
            </tr>
            <tr>
                <th colspan="8" class="table_header">
                    用车
                </th>
            </tr>
            <tr>
                <td colspan="8" style="padding:0px;">
                    <table>
                        <tr>
                            <th>
                                司机
                            </th>
                            <td>
                                <%= h @tour_group.vehicle.driver.name unless @tour_group.vehicle.nil? || @tour_group.vehicle.driver.nil? %>
                            </td>
                            <th>
                                车型
                            </th>
                            <td>
                                <%= h @tour_group.vehicle.vehicle_model.name unless @tour_group.vehicle.nil? || @tour_group.vehicle.vehicle_model.nil? %>
                            </td>
                            <th>
                                车费
                            </th>
                            <td>
                                <%= number_to_rmb @tour_group.vehicle.travel_cost unless @tour_group.vehicle.nil? %>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                用车记录
                            </th>
                            <td colspan="5" style="background-color: #f0f0f0;">
                                <div id="vehicle_rent_records_div">
                                    <%
                                    unless @tour_group.vehicle.nil?
                                    use_days = @tour_group.vehicle.vehicle_rent_records.collect{|x| x.day}
                                    all_days = (@tour_group.during_start..@tour_group.during_end).to_a unless @tour_group.during_start.nil? || @tour_group.during_end.nil?
                                    all_days ||= use_days
                                    for d in all_days
                                    use = use_days.include?(d)
                                    if use %>
                                    <div class="vehicle_use" style="cursor: default">
                                        <%= d.day %>
                                        <p>
                                            用车
                                        </p>
                                    </div>
                                    <% else %>
                                    <div class="vehicle_unuse" style="cursor: default">
                                        <%= d.day %>
                                        <p>
                                            未用
                                        </p>
                                    </div>
                                    <% end %>
                                    <% end %>
                                    <% end %>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
			<tr>
				<th>北京成本</th>
				<td colspan="7">
					<%= number_to_rmb @tour_group.bj_cost %>
				</td>
			</tr>
            <tr>
                <th colspan="8" class="table_header">
                    进店
                </th>
            </tr>
            <tr>
                <td colspan="8" style="padding:0px;">
                    <table>
                        <tr>
                            <th>
                                商店
                            </th>
                            <th>
                                购物额
                            </th>
                            <th>
                                流水
                            </th>
                            <th>
                                人头费
                            </th>
                            <th>
                                人数
                            </th>
                            <th>
                                人头费总计
                            </th>
                            <th>
                                进店小计
                            </th>
                            <th>
                                结账情况
                            </th>
                        </tr>
                        <%
                        unless @tour_group.shopping.nil?
                        for record in @tour_group.shopping.shopping_records %>
                        <tr>
                            <td>
                                <%= h record.shop.name unless record.shop.nil? %>
                            </td>
                            <td>
                                <%= number_to_rmb record.shopping_cost %>
                            </td>
                            <td>
                                <%= number_to_rmb record.flow_cost %>
                            </td>
                            <td>
                                <%= number_to_rmb record.unit_price %>
                            </td>
                            <td>
                                <%= h record.number_of_people %>
                            </td>
                            <td>
                                <%= number_to_rmb record.people_cost %>
                            </td>
                            <td>
                                <%= number_to_rmb record.total_cost %>
                            </td>
                            <td>
                                <%= record.is_checkedout ? "已结" : "未结" %>
                            </td>
                        </tr>
                        <% end %><% end %>
                    </table>
                </td>
            </tr>
            <tr>
                <th>
                    导游返佣金
                </th>
                <td>
                    <%= number_to_rmb @tour_group.shopping.commission_from_guide unless @tour_group.shopping.nil? %>
                </td>
                <th>
                    返还组团社
                </th>
                <td colspan="5">
                    <%= number_to_rmb @tour_group.shopping.return_to_customer unless @tour_group.shopping.nil? %>
                </td>
            </tr>
            <tr>
                <th colspan="8" class="table_header">
                    外地支出
                </th>
            </tr>
            <tr>
                <td colspan="8" style="padding:0px;">
                    <table>
                        <tr>
                            <th>
                                房费
                            </th>
                            <th>
                                地接费
                            </th>
                            <th>
                                机票
                            </th>
                            <th>
                                火车票
                            </th>
                            <th>
                                船票
                            </th>
                            <th>
                                小计
                            </th>
                        </tr>
                        <tr>
                            <td>
                                <%= number_to_rmb @tour_group.outer_expense.lodging_cost unless @tour_group.outer_expense.nil? %>
                            </td>
                            <td>
                                <%= number_to_rmb @tour_group.outer_expense.acceptance_cost unless @tour_group.outer_expense.nil? %>
                            </td>
                            <td>
                                <%= number_to_rmb @tour_group.outer_expense.airticket_cost unless @tour_group.outer_expense.nil? %>
                            </td>
                            <td>
                                <%= number_to_rmb @tour_group.outer_expense.trainticket_cost unless @tour_group.outer_expense.nil? %>
                            </td>
							<td>
                                <%= number_to_rmb @tour_group.outer_expense.boatticket_cost unless @tour_group.outer_expense.nil? %>
                            </td>
                            <td>
                                <%= number_to_rmb @tour_group.outer_expense.total_cost unless @tour_group.outer_expense.nil? %>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <th>
                    收费
                </th>
                <td>
                    <%= number_to_rmb @tour_group.revenue %>
                </td>
				     <th>
                    总成本
                </th>
                <td>
                    <%= number_to_rmb @tour_group.total_cost %>
                </td>
                <th>
                    负责人
                </th>
                <td colspan="3">
                    <%= h @tour_group.owner.name unless @tour_group.owner.nil? %>
                </td>
            </tr>
            <tr>
                <th>
                    做团利润
                </th>
                <td>
                    <%= number_to_rmb @tour_group.profit %>
                </td>
                <th>
                    进店总计
                </th>
                <td>
                    <%= number_to_rmb @tour_group.shopping.total_cost unless @tour_group.shopping.nil? %>
                </td>
                <th>
                    总利润
                </th>
                <td colspan="3">
                    <%= number_to_rmb @tour_group.total_profit %>
                </td>
            </tr>
        </table>
    </div>
</div>
